
// source idl: com.erp.test.ao.idl.HelloworldAo.java

#ifndef HELLOWORLDAO_STUB_4_APP_H
#define HELLOWORLDAO_STUB_4_APP_H

#include <string>
#include <sstream>
#include "app_platform/cmd_obj.h"
#include "c2cent/base/basestub4app.h"
#include "app_platform/cntl_info.h"
#include "app_platform/intf_serializable.h"
#include "app_platform/intf_service_object.h"
#include "intf_helloworldao.h"

namespace com
{
namespace erp
{
namespace test
{
namespace ao
{
	#define HELLOWORLDAO_STUB4APP_VERSION "COM_ERP_TEST_AO___HELLOWORLDAO__STUB4APP_VERSION__1.0 2013-09-30 17:49:46"
    const std::string HELLOWORLDAO_STUB4APP_NOUSE = HELLOWORLDAO_STUB4APP_VERSION;

	const uint32_t HELLOWORLDAO_SAYHELLO_REQ_CMD_ID = 0xc0281801; /// 请求命令号
	const uint32_t HELLOWORLDAO_SAYHELLO_RESP_CMD_ID = 0xc0288801; /// 回应命令号
	


	const uint16_t HELLOWORLDAO_MAX_PROTOCAL_VERSION = 2; //>平台支持的最大协议版本号

///////////////////////////// STRUCTS /////////////////////////////////////////////////
	/**
	 *
 	 * 
	 *
	 *
 	 * @date 2013-09-30 17:49:47
 	 * @version 0
	 */	
	struct CSayHelloReq : public IServiceObject, public ISerializableXML
	{
		std::string NickName;
		uint32_t Age;
		
	    virtual uint32_t getCmdId() const { return HELLOWORLDAO_SAYHELLO_REQ_CMD_ID; }
		virtual bool Serialize(CByteStreamNetwork& bs)
		{
			//检查协议的版本号
		    //if(bs.getVersion() > HELLOWORLDAO_MAX_PROTOCAL_VERSION)
		    //return false;
			bs & NickName;
		    return bs.isGood();
		}
	    virtual void Dump(std::ostream& os)	{}
	
		virtual bool FromXML(const std::string& sXMLContent) { return true; }
		virtual bool ToXML(std::string& sXMLContent) { return true; }
	};
	
	/**
	 *
 	 * 
	 *
 	 * @date 2013-09-30 17:49:47
 	 * @version 0
	 */	
	struct CSayHelloResp : public IServiceObject, public ISerializableXML
	{
		uint32_t dwResult;
		uint32_t Age;
	
	    virtual uint32_t getCmdId() const { return HELLOWORLDAO_SAYHELLO_RESP_CMD_ID; }
		virtual bool Serialize(CByteStreamNetwork& bs)
		{
		    bs & dwResult;
			bs & Age;
		    return bs.isGood();
		}
	    virtual void Dump(std::ostream& os)	{}
	
		virtual bool FromXML(const std::string& sXMLContent) { return true; }
		virtual bool ToXML(std::string& sXMLContent) { return true; }
	};
	class CHelloworldAoStub4App : public c2cent::CBaseStub4App, public IHelloworldAo,public IHelloworldAoAsyc{
		public:
			uint32_t SayHello(
				const CCntlInfo& rCntlInfo,
				const std::string& NickName,
				uint32_t& Age
			);
			
			uint32_t SendSayHello(
				const CCntlInfo& rCntlInfo,
				const std::string& NickName
		    );
		    uint32_t RecvSayHello(
				const CCntlInfo& rCntlInfo,
				uint32_t& Age
		    );
		    
		    uint32_t RecvSayHello(
		  		CCmdObj& rCmd,
				uint32_t& Age
		    );
		    
		    uint32_t GetSayHelloRespCmd(
		    );
	};
	
	/**
	 *
 	 * say hello
	 *
		 *@param String NickName: 输入昵称 				
		 *@param uint32_t Age: 返回年龄信息 		
     *
     *@return uint32_t : 0(成功) 其它失败
	 */	
	inline uint32_t CHelloworldAoStub4App::SayHello(
				const CCntlInfo& rCntlInfo,
				const std::string& NickName,
				uint32_t& Age
	)
	{
		CSayHelloReq oReq;
			oReq.NickName = NickName;
			oReq.Age = Age;
	
		CCntlInfo* pCntlInfo = const_cast<CCntlInfo*>(&rCntlInfo);
	    m_pSvcCntl = reinterpret_cast<IServiceControl*>(pCntlInfo->getCntl());
	    if (m_pSvcCntl == NULL)
        {
            m_sErrMsg = "error, rCntlInfo is temporary variable";
            return 0xEE0041;
        }
	    int iRetCode = 0;
	    if((iRetCode = m_pSvcCntl->putSvcObj(&oReq, pCntlInfo->getRouteKey())) != 0)
	    {
	    	m_sErrMsg = "DoRequest failed.";
	        return iRetCode;
	    }
	
	    if((iRetCode = m_pSvcCntl->schedule()) != 0)
	    {
	        m_sErrMsg = "schedule failed.";
	        return 0xFFF2;
	    }
	    
	    CCmdObj& rCmd = m_pSvcCntl->getRespObj();
	    if(!rCmd.isValid(HELLOWORLDAO_SAYHELLO_RESP_CMD_ID))
	    {
	    	std::stringstream oss;
            oss << "Cmd not match: "
                << "expected cmd=" << std::hex << HELLOWORLDAO_SAYHELLO_RESP_CMD_ID << std::dec << " != "
                << "actualed cmd=" << std::hex << rCmd.getCmdId() << std::dec;
            m_sErrMsg = oss.str();
            return 0xEE0029;
	    }
	    
	    char* pBuf = NULL; uint32_t nLen = 0;
	    rCmd.getBuffer(pBuf, nLen);
	    CByteStreamNetwork bs(pBuf, nLen);
	    bs.isStoring(false);
	    
	    CSayHelloResp oResp;
	    if(!oResp.Serialize(bs))
	    {
	        m_sErrMsg = "Resp.Serialize(bs) failed";
	        return 0xEE0030;
	    }
			Age  = oResp.Age;
	    
	    return oResp.dwResult;
	}
	inline uint32_t CHelloworldAoStub4App::SendSayHello(
				const CCntlInfo& rCntlInfo,
				const std::string& NickName
	)
	{
	    CSayHelloReq oReq;
			oReq.NickName = NickName;
	
		CCntlInfo* pCntlInfo = const_cast<CCntlInfo*>(&rCntlInfo);
	    m_pSvcCntl = reinterpret_cast<IServiceControl*>(pCntlInfo->getCntl());
	    if (m_pSvcCntl == NULL)
        {
            m_sErrMsg = "error, rCntlInfo is temporary variable";
            return 0xEE0041;
        }
	    int iRetCode = 0;
	    if((iRetCode = m_pSvcCntl->putSvcObj(&oReq, pCntlInfo->getRouteKey())) != 0)
	    {
	    	m_sErrMsg = "DoRequest failed.";
	        return iRetCode;
	    }
		return 0;
	}
	inline uint32_t CHelloworldAoStub4App::RecvSayHello(
				const CCntlInfo& rCntlInfo,
				uint32_t& Age
	)
	{
		CCntlInfo* pCntlInfo = const_cast<CCntlInfo*>(&rCntlInfo);
	    m_pSvcCntl = reinterpret_cast<IServiceControl*>(pCntlInfo->getCntl());
	    CCmdObj& rCmd = m_pSvcCntl->getRespObj();
	    if(!rCmd.isValid(HELLOWORLDAO_SAYHELLO_RESP_CMD_ID))
	    {
	    	std::stringstream oss;
            oss << "Cmd not match: "
                << "expected cmd=" << std::hex << HELLOWORLDAO_SAYHELLO_RESP_CMD_ID << std::dec << " != "
                << "actualed cmd=" << std::hex << rCmd.getCmdId() << std::dec;
            m_sErrMsg = oss.str();
	        return 0xEE0031;
	    }
	    
	    char* pBuf = NULL; uint32_t nLen = 0;
	    rCmd.getBuffer(pBuf, nLen);
	    CByteStreamNetwork bs(pBuf, nLen);
	    bs.isStoring(false);
	    
	    CSayHelloResp oResp;
	    if(!oResp.Serialize(bs))
	    {
	        m_sErrMsg = "Resp.Serialize(bs) failed";
	        return 0xEE0032;
	    }
			Age  = oResp.Age;
	    
	    return oResp.dwResult;
	}
	
	inline uint32_t CHelloworldAoStub4App::RecvSayHello(
		  		CCmdObj& rCmd,
				uint32_t& Age
	)
	{	    
	    char* pBuf = NULL; uint32_t nLen = 0;
	    rCmd.getBuffer(pBuf, nLen);
	    CByteStreamNetwork bs(pBuf, nLen);
	    bs.isStoring(false);
	    
	    CSayHelloResp oResp;
	    if(!oResp.Serialize(bs))
	    {
	        m_sErrMsg = "Resp.Serialize(bs) failed";
	        return 0xEE0033;
	    }
			Age  = oResp.Age;
	    
	    return oResp.dwResult;
	}
	
	inline uint32_t CHelloworldAoStub4App::GetSayHelloRespCmd(
	)
	{	    
	    return HELLOWORLDAO_SAYHELLO_RESP_CMD_ID;
	}	
		
}
}
}
}

#endif /* HELLOWORLDAO_STUB_4_APP_H */
